package handlers

import (
	"attitude/models"
	"fmt"
	"github.com/gin-gonic/gin"
)

func Add(c *gin.Context) {
	fmt.Println(11)
	title := c.PostForm("title")
	context := c.PostForm("context")
	if title == "" || context == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "景点标题或景点详情不能为空",
		})
		return
	}
	fmt.Println(title, context)

	attach := models.Attach{
		Title:   title,
		Context: context,
	}
	err := models.DB.Debug().Create(&attach).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}
